#!/usr/bin/env php
<?php
class db
{
    public static $conn;
}

function main()
{
    try
    {
        $host="localhost";
        //$host="vmusdev";
        //db::$conn=new PDO("mysql:host=$host;dbname=test;charset=utf8",
        db::$conn=new PDO("mysql:host=$host;dbname=test",
                "dbuser", "dbuser");
        db::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        db::$conn->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
        db::$conn->exec("set names utf8");

        $rs=db::$conn->query("select * from my_emp where empno<100");
        $rows=$rs->fetchAll(PDO::FETCH_ASSOC);
        foreach($rows as $row)
        {
            printf("%s\n", $row['name']);
        }
        $rs->closeCursor();
        unset($rs);
        db::$conn=null;
    }
    catch(PDOException $e)
    {
        printf("connect to db fail: %s\n", $e->getMessage());
        db::$conn=null;
        return 1;
    }

    sleep(100);
    return 0;
}

main();
sleep(100);
?>
